import re
from datetime import datetime, date
from typing import List, Optional
from pydantic import BaseModel, Field, validator, EmailStr, IPvAnyAddress

from enum import Enum


class DelBaseModel(BaseModel):
    uuid: int = Field(..., description="数据的uuid")


class PostHostDateTask(BaseModel):
    quality_date: date = Field(..., description="日期数据")


class ClassesServerInfo(str, Enum):
    class1 = 'ECS服务器'
    class2 = 'k8s_deployment'
    class3 = 'k8s_statefulset'


class ClassesHostInfo(str, Enum):
    class1 = 'ECS服务器'
    class2 = 'k8s集群node节点'


class TypeServerInfo(str, Enum):
    class1 = 'java-service'
    class2 = 'python-service'
    class3 = 'node-service'
    class4 = 'h5-service'


class PostServerInfo(BaseModel):
    name: str = Field(..., description="应用服务的名字")
    type: TypeServerInfo = Field(TypeServerInfo.class1, description="应用服务类型")
    classes: ClassesServerInfo = Field(ClassesServerInfo.class1, description="应用服务部署归类")
    department: str = Field(..., description="所属部门")
    number: int = Field(..., description="服务数量")
    cpu_request: int = Field(..., description="cpu最低配额(单位:核)")
    cpu_limit: int = Field(..., description="cpu最高配额(单位:核)")
    mem_request: int = Field(..., description="内存最低配额(单位:G)")
    mem_limit: int = Field(..., description="内存最高配额(单位:G)")
    port: int = Field(..., description="服务的监听端口")
    deploy_nodes: List[str] = Field(..., description="部署的节点名称列表")
    comment: Optional[str] = Field("", description="告警指标的说明")


class PutServerInfo(BaseModel):
    uuid: int = Field(..., description="应用服务uuid")
    type: TypeServerInfo = Field(TypeServerInfo.class1, description="应用服务类型")
    classes: ClassesServerInfo = Field(ClassesServerInfo.class1, description="应用服务部署归类")
    department: str = Field(..., description="所属部门")
    number: int = Field(..., description="服务数量")
    cpu_request: int = Field(..., description="cpu最低配额(单位:核)")
    cpu_limit: int = Field(..., description="cpu最高配额(单位:核)")
    mem_request: int = Field(..., description="内存最低配额(单位:G)")
    mem_limit: int = Field(..., description="内存最高配额(单位:G)")
    port: int = Field(..., description="服务的监听端口")
    deploy_nodes: List[str] = Field(..., description="部署的节点名称列表")
    comment: Optional[str] = Field("", description="告警指标的说明")


class PostServerDateTask(BaseModel):
    quality_date: date = Field(..., description="日期数据")


class PaintClassesServer(str, Enum):
    class1 = 'all'
    class2 = 'k8s_deployment'
    class3 = 'k8s_statefulset'
    class4 = 'ECS服务器'


class PaintClassesHost(str, Enum):
    class1 = 'all'
    class2 = 'k8s集群node节点'
    class3 = 'ECS服务器'


class PaintClusterName(str, Enum):
    k8s = 'k8s-cluster'
    database = 'db-cluster'
    bigdata_realtime = "bigdata-realtime-cluster"
    bigdata_offline = "bigdata-offline-cluster"


class PaintTimeRange(str, Enum):
    one_hours = 'one_hours'
    two_hours = 'two_hours'
    four_hours = 'four_hours'
    six_hours = 'six_hours'
    twelve_hours = 'twelve_hours'
    one_day = 'one_day'
    three_day = 'three_day'
    seven_day = 'seven_day'


class PaintPromMetrics(str, Enum):
    cpu = 'cpu'
    mem = 'mem'
    diskio = 'diskio'
    diskread = 'diskread'
    diskwritten = 'diskwritten'


class ReportProcessIo(BaseModel):
    report_time: Optional[datetime] = Field(..., description="数据上报时间")
    hostname: str = Field(..., regex="^[-.a-zA-Z0-9_]+$", description="主机名称")
    ip: IPvAnyAddress = Field(..., description="主机地址")
    pid: int = Field(..., description="进程编号")
    user: str = Field(..., description="系统用户")
    disk_read: str = Field(..., description="磁盘读速率")
    disk_write: str = Field(..., description="磁盘写速率")
    io: str = Field(..., description="维护结束时间")
    command: str = Field(..., description="进程名称")


class ReportProcessIoList(BaseModel):
    items: List[ReportProcessIo]
